Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-logger

Package Overview
Dependencies
Maintainers
12
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-logger

egg logger

  • 1.8.0
  • latest-1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
35K
decreased by-10.25%
Maintainers
12
Weekly downloads
 
Created
Source

egg-logger

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Egg logger.

Including two base class, Logger and Transport:

  • Transport: Save log to file, stdout/stderr and network.
  • Logger: A logger can contains multi transports.

Install

$ npm i egg-logger

Usage

Create a Logger and add a file Transport.

const Logger = require('egg-logger').Logger;
const FileTransport = require('egg-logger').FileTransport;
const ConsoleTransport = require('egg-logger').ConsoleTransport;

const logger = new Logger();
logger.set('file', new FileTransport({
  file: '/path/to/file',
  level: 'INFO',
}));
logger.set('console', new ConsoleTransport({
  level: 'DEBUG',
}));
logger.debug('debug foo'); // only output to stdout
logger.info('info foo');
logger.warn('warn foo');
logger.error(new Error('error foo'));

Enable / Disable Transport

logger.disable('file');
logger.info('info'); // output nothing
logger.enable('file');
logger.info('info'); // output 'info' string

Redirect

Redirect error log to other logger.

logger.redirect('error', errorLogger);
logger.error(new Error('print to errorLogger')); // equal to `errorLogger.error`

Reload

logger.reload(); // will close the exists write stream and create a new one.

Custom Transport

You can make your own Transport for logging,e.g.: send log to your logging server.

const urllib = require('urllib');
const Transport = require('egg-logger').Transport;

class UrllibTransport extends Transport {

  log(level, args, meta) {
    const msg = super.log(level, args, meta);
    return urllib.request('url?msg=' + msg);
  }
}

const logger = new Logger();
logger.set('remote', new UrllibTransport({
  level: 'DEBUG',
}));
logger.info('info');

License

MIT

FAQs

Package last updated on 07 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc